home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / h_v_axes.cpp < prev    next >
C/C++ Source or Header  |  1994-11-17  |  5KB  |  180 lines

  1. #include "h_v_axes.h"
  2.  
  3. HV_Axes::HV_Axes(int l, double start, double end, int tick_no, int* t,
  4.         int s_tick_no, int* s, char** lab)
  5.  : Axe(l, start, end, tick_no, t, s_tick_no, s,
  6.          lab)
  7.                  {}
  8. //////////////////////
  9. void HV_Axes::show_labels(loc lt)
  10.     {
  11.     int hor_j = CENTER_TEXT;
  12.     int ver_j = TOP_TEXT;
  13.  
  14.     if(dir == VERT_AXE)
  15.     {
  16.     if(type == NORMAL_AXE)
  17.         hor_j = RIGHT_TEXT;
  18.     else
  19.         hor_j = LEFT_TEXT;
  20.     ver_j = CENTER_TEXT;
  21.     }
  22.     else
  23.     {
  24.     if(type == REVERSE_AXE)
  25.         ver_j = BOTTOM_TEXT;
  26.     }
  27.  
  28.     drawTool->load("litt.chr");
  29.  
  30.     drawTool->settextjustify(hor_j, ver_j);
  31.  
  32.     for(int i = 0; i < ticks_no; i++)
  33.     {
  34.     loc pos = get_label_pos(lt, i);
  35.     if((dir == HORIZ_AXE && pos.X > len_scr + lt.X)
  36.         || (dir == VERT_AXE && pos.Y > len_scr + lt.Y))
  37.         break;
  38.  
  39.     if(!text_dir)
  40.         ;//pos.Y += drawTool->getheight();
  41.     else
  42.         pos.Y += drawTool->gettextwidth(labels[i])/2;
  43.  
  44. //    drawTool->center = pos;
  45.  
  46.     drawTool->outtextxy(pos.X, pos.Y, labels[i], text_dir);
  47.     }
  48.     }
  49. //////////////////////
  50. void HV_Axes::set_type(int t, int d, int td)
  51.     {
  52.     type = t;
  53.     dir = d;
  54.     text_dir = td;
  55.     }
  56. ///////////////////////////
  57. loc HV_Axes::get_label_pos(loc lt, int n)
  58.     {
  59.     loc pos;
  60.     int sh = type == NORMAL_AXE ? 1 : -1;
  61.     if(dir == HORIZ_AXE)
  62.     {
  63.     pos.X = lt.X + (long)ticks[n] * len_scr / 10000;
  64.     pos.Y = lt.Y + drawTool->getheight() * sh;
  65.     }
  66.     else
  67.     {
  68.     pos.Y = lt.Y + len_scr - (long)ticks[n] * len_scr / 10000;
  69.     pos.X = lt.X - drawTool->getheight() * sh;
  70.     }
  71.  
  72.     return pos;
  73.     }
  74. //////////////////////////////////////
  75. void HV_Axes::show_axe(loc lt, int ax_col)
  76.     {
  77.     drawTool->setlinestyle(1, SOLID_LINE);
  78.     drawTool->setcolor(ax_col);
  79.  
  80.     int sx = 0;
  81.     int sy = 0;
  82.     if(dir == HORIZ_AXE)
  83.     sx = 1;
  84.     else
  85.         sy = 1;
  86.     drawTool->line(lt.X, lt.Y, lt.X + sx * len_scr, lt.Y + sy * len_scr);
  87.     if(dir == HORIZ_AXE)
  88.     {
  89.     for(int i = 0; i < ticks_no; i++)
  90.         drawTool->line(lt.X + (long)ticks[i] * len_scr / 10000, //ticks[ticks_no - 1],
  91.          lt.Y + 4,
  92.          lt.X + (long)ticks[i] * len_scr / 10000, //ticks[ticks_no - 1],
  93.          lt.Y - 4);
  94.     for(i = 0; i < sub_ticks_no; i++)
  95.         drawTool->line(lt.X + (long)sub_ticks[i] * len_scr / 10000, //sub_ticks[sub_ticks_no - 1],
  96.          lt.Y + 2,
  97.          lt.X + (long)sub_ticks[i] * len_scr / 10000, //sub_ticks[sub_ticks_no - 1],
  98.          lt.Y - 2);
  99.     }
  100.     else
  101.     {
  102.     for(int i = 0; i < ticks_no; i++)
  103.         drawTool->line(lt.X - 4,
  104.          lt.Y + len_scr - (long)ticks[i] * len_scr / 10000, //ticks[ticks_no - 1],
  105.          lt.X + 4,
  106.          lt.Y + len_scr - (long)ticks[i] * len_scr / 10000); //ticks[ticks_no - 1]);
  107.     for(i = 0; i < sub_ticks_no; i++)
  108.         drawTool->line(lt.X - 2,
  109.         lt.Y + len_scr - (long)sub_ticks[i]
  110.             * len_scr / 10000, //sub_ticks[sub_ticks_no - 1],
  111.          lt.X + 2,
  112.          lt.Y + len_scr - (long)sub_ticks[i]
  113.             * len_scr / 10000); //sub_ticks[sub_ticks_no - 1]);
  114.     }
  115.     }
  116.  
  117. /*
  118. void main()
  119.     {
  120.     int gdriver = DETECT, gmode;
  121.     initgraph(&gdriver, &gmode, "");
  122.  
  123.     drawTool = new KH_Paint();   // See KHPAINT.H
  124.     drawTool->rotate(loc(320, 240), 15);
  125.  
  126.     HV_Axes a(300, -20, 80);
  127.     a.set_type(NORMAL_AXE, HORIZ_AXE);
  128.     a.draw_axe(loc(40, 320), LIGHTBLUE, YELLOW);
  129.  
  130.     a.set_type(REVERSE_AXE, HORIZ_AXE);
  131.     a.draw_axe(loc(40, 20), LIGHTBLUE, YELLOW);
  132.  
  133.     a.set_type(NORMAL_AXE, VERT_AXE);
  134.     a.draw_axe(loc(40, 20), LIGHTBLUE, YELLOW);
  135.  
  136.     a.set_type(REVERSE_AXE, VERT_AXE);
  137.     a.draw_axe(loc(340, 20), LIGHTBLUE, YELLOW);
  138.  
  139.     HV_Axes a2(200, -25, 80);
  140.     a2.set_type(NORMAL_AXE, HORIZ_AXE);
  141.     a2.draw_axe(loc(420, 20), LIGHTBLUE, YELLOW);
  142.  
  143.     HV_Axes a3(200, -122, 83);
  144.     a3.set_type(NORMAL_AXE, HORIZ_AXE, VERT_DIR);
  145.     a3.draw_axe(loc(420, 60), LIGHTBLUE, YELLOW);
  146.  
  147.     HV_Axes a4(200, -5635, -3558);
  148.     a4.set_type(NORMAL_AXE, HORIZ_AXE, VERT_DIR);
  149.     a4.draw_axe(loc(420, 140), LIGHTBLUE, YELLOW);
  150.  
  151.  
  152.     HV_Axes a5(200, 0, 1180);
  153.     a5.set_type(NORMAL_AXE, HORIZ_AXE, VERT_DIR);
  154.     a5.draw_axe(loc(420, 240), LIGHTBLUE, YELLOW);
  155.  
  156.     int t[] = { 0, 5000, 10000 };
  157.     int s[] = { 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000 };
  158.     char* lab[] = { "First", "Second", "Third" };
  159.  
  160.     HV_Axes a1(200, 0, 0, 3, t, 9, s, lab);
  161.  
  162.     a1.set_type(NORMAL_AXE, HORIZ_AXE);
  163.     a1.draw_axe(loc(60, 300), LIGHTGREEN, LIGHTRED);
  164.  
  165.     a1.set_type(REVERSE_AXE, HORIZ_AXE);
  166.     a1.draw_axe(loc(60, 270), LIGHTGREEN, LIGHTRED);
  167.  
  168.     a1.set_type(NORMAL_AXE, VERT_AXE);
  169.     a1.draw_axe(loc(100, 40), LIGHTGREEN, LIGHTRED);
  170.  
  171.     a1.set_type(REVERSE_AXE, VERT_AXE);
  172.     a1.draw_axe(loc(120, 40), LIGHTGREEN, LIGHTRED);
  173.  
  174.     delete drawTool;   // See KHPAINT.H
  175.     closegraph();
  176.     }
  177. */
  178.  
  179.  
  180.